package ipad.asia.controller;

import ipad.asia.entity.PunishConsumer;
import ipad.asia.entity.PunishEnterprise;
import ipad.asia.service.punish.PunishConsumerFeign;
import ipad.asia.service.punish.PunishEnterpriseFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.jar.Attributes;

@Controller
public class DealController {
    @Autowired
    private PunishConsumerFeign punishConsumerFeign;
    @Autowired
    private PunishEnterpriseFeign punishEnterpriseFeign;
    @RequestMapping("/deal/shop")
     public String dealShop(@RequestParam(value = "id",required = false)int id,
                            @RequestParam(value = "deal",required = false)String deal,
                            RedirectAttributes arr,Model model){
        if(deal==null){
            PunishEnterprise punishEnterprise = punishEnterpriseFeign.findById(id);
            model.addAttribute("report",punishEnterprise);
            model.addAttribute("message","你这次并没造成修改");
            return "shopDetail";
        }
        if(deal.equals("yes")){
            PunishEnterprise punishEnterprise = punishEnterpriseFeign.findById(id);
            punishEnterpriseFeign.update(1,punishEnterprise.getSerious()+1,"同意",id);
            arr.addAttribute("message"+"确认成功举报！");
            return "redirect:/report/shopList";
        }
       else {
            PunishEnterprise punishEnterprise = punishEnterpriseFeign.findById(id);
            punishEnterpriseFeign.update(1,punishEnterprise.getSerious()+1,"不同意",id);
            arr.addAttribute("message"+"你已不同意举报！");
           return "redirect:/report/shopList";
        }
    }


    @RequestMapping("/deal/consumer")
    public String dealConsumer(@RequestParam(value = "id",required = false)int id,
                               @RequestParam(value = "deal",required = false)String deal,
                           RedirectAttributes arr,Model model){
        if(deal==null){
            PunishConsumer punishConsumer = punishConsumerFeign.findById(id);
            model.addAttribute("report",punishConsumer);
            model.addAttribute("message","你这次并没造成修改");
            return "consumerDetail";
        }
        if(deal.equals("yes")) {
            PunishConsumer punishConsumer = punishConsumerFeign.findById(id);
            punishConsumerFeign.update(1, punishConsumer.getSerious() + 1,"同意", id);
            arr.addAttribute("message" + "确认成功举报！");
            return "redirect:/report/ConsumerList";
        }
          else {
            PunishConsumer punishConsumer = punishConsumerFeign.findById(id);
            punishConsumerFeign.update(1, punishConsumer.getSerious() + 1,"同意", id);
            arr.addAttribute("message"+"你已不同意举报！");
            return "redirect:/report/ConsumerList";
        }
    }
}
